Fossil SCM

Minor cleanups and tinkering in /json/dir.

stephan 2012-03-18 16:37 trunk
Commit c1963c49b0a09e262ae261dc4d47ed57b56f7c45
1 file changed +27 -20
+27 -20
--- src/json_dir.c
+++ src/json_dir.c
@@ -106,11 +106,11 @@
106106
** Subdirectory names begin with "/". This causes them to sort
107107
** first and it also gives us an easy way to distinguish files
108108
** from directories in the loop that follows.
109109
*/
110110
db_multi_exec(
111
- "CREATE TEMP TABLE localfiles(x UNIQUE NOT NULL %s, u, sz);",
111
+ "CREATE TEMP TABLE localfiles(n UNIQUE NOT NULL %s, u, sz, mtime DEFAULT NULL);",
112112
filename_collation()
113113
);
114114
115115
if( zCI ){
116116
Stmt ins;
@@ -118,12 +118,15 @@
118118
ManifestFile *pPrev = 0;
119119
int nPrev = 0;
120120
int c;
121121
122122
db_prepare(&ins,
123
- "INSERT OR IGNORE INTO localfiles VALUES(pathelement(:x,0), :u, "
124
- "(SELECT size from blob where uuid=:s)"
123
+ "INSERT OR IGNORE INTO localfiles VALUES("
124
+ /*0*/ "pathelement(:x,0),"
125
+ /*1*/ ":u, "
126
+ /*2*/ "(SELECT size from blob where uuid=:s), "
127
+ /*3: TODO: mtime*/" NULL"
125128
")"
126129
);
127130
manifest_file_rewind(pM);
128131
while( (pFile = manifest_file_next(pM,0))!=0 ){
129132
if( nD>0
@@ -139,10 +142,11 @@
139142
continue;
140143
}
141144
db_bind_text(&ins, ":x", &pFile->zName[nD]);
142145
db_bind_text(&ins, ":u", pFile->zUuid);
143146
db_bind_text(&ins, ":s", pFile->zUuid);
147
+ /*db_bind_text(&ins, ":u3", pFile->zUuid);*/
144148
db_step(&ins);
145149
db_reset(&ins);
146150
pPrev = pFile;
147151
for(nPrev=0; (c=pPrev->zName[nD+nPrev]) && c!='/'; nPrev++){}
148152
if( c=='/' ) nPrev++;
@@ -150,33 +154,33 @@
150154
db_finalize(&ins);
151155
}else if( zD && *zD ){
152156
if( filenames_are_case_sensitive() ){
153157
db_multi_exec(
154158
"INSERT OR IGNORE INTO localfiles"
155
- " SELECT pathelement(name,%d), NULL, NULL FROM filename"
159
+ " SELECT pathelement(name,%d), NULL, NULL, NULL FROM filename"
156160
" WHERE name GLOB '%q/*'",
157161
nD, zD
158162
);
159163
}else{
160164
db_multi_exec(
161165
"INSERT OR IGNORE INTO localfiles"
162
- " SELECT pathelement(name,%d), NULL FROM filename"
166
+ " SELECT pathelement(name,%d), NULL, NULL, NULL FROM filename"
163167
" WHERE name LIKE '%q/%%'",
164168
nD, zD
165169
);
166170
}
167171
}else{
168172
db_multi_exec(
169173
"INSERT OR IGNORE INTO localfiles"
170
- " SELECT pathelement(name,0), NULL FROM filename"
174
+ " SELECT pathelement(name,0), NULL, NULL, NULL FROM filename"
171175
);
172176
}
173177
174178
if(zCI){
175
- db_prepare( &q, "SELECT x as name, u as uuid, sz as size FROM localfiles ORDER BY x");
179
+ db_prepare( &q, "SELECT n as name, u as uuid, sz as size FROM localfiles ORDER BY n");
176180
}else{/* UUIDs are all NULL. */
177
- db_prepare( &q, "SELECT x as name FROM localfiles ORDER BY x");
181
+ db_prepare( &q, "SELECT n as name FROM localfiles ORDER BY n");
178182
}
179183
180184
zKeyName = cson_new_string("name",4);
181185
cson_value_add_reference( cson_string_value(zKeyName) );
182186
zKeyUuid = cson_new_string("uuid",4);
@@ -189,16 +193,18 @@
189193
}
190194
191195
zPayload = cson_new_object();
192196
cson_object_set_s( zPayload, zKeyName,
193197
json_new_string((zD&&*zD) ? zD : "/") );
198
+#if 0
194199
if(zUuid){
195200
cson_object_set_s( zPayload, zKeyUuid,
196201
cson_string_value(cson_new_string(zUuid, strlen(zUuid))) );
197202
}
198
- if( zCI ){
199
- cson_object_set( zPayload, "checkin", json_new_string(zCI) );
203
+#endif
204
+ if( zUuid ){
205
+ cson_object_set( zPayload, "checkin", json_new_string(zUuid) );
200206
}
201207
202208
while( (SQLITE_ROW==db_step(&q)) ){
203209
cson_value * name = NULL;
204210
char const * n = db_column_text(&q,0);
@@ -214,22 +220,23 @@
214220
cson_object_set_s(zEntry, zKeyIsDir, cson_value_true() );
215221
} else{
216222
name = json_new_string( n );
217223
}
218224
cson_object_set_s(zEntry, zKeyName, name );
219
- if( zCI ){
225
+ if( zCI && !isDir){
226
+ /* don't add the uuid/size for dir entries - that data refers
227
+ to one of the files in that directory :/. */
220228
char const * u = db_column_text(&q,1);
221229
sqlite_int64 const sz = db_column_int64(&q,2);
222
- if(!isDir){
223
- /* don't add the uuid/size for dir entries - that data refers
224
- to one of the files in that directory :/. */
225
- if(u && *u){
226
- cson_object_set_s(zEntry, zKeyUuid, json_new_string( u ) );
227
- }
228
- cson_object_set_s(zEntry, zKeySize,
229
- cson_value_new_integer( (cson_int_t)sz ));
230
- }
230
+ /*sqlite_int64 const ts = db_column_int64(&q,3);*/
231
+ if(u && *u){
232
+ cson_object_set_s(zEntry, zKeyUuid, json_new_string( u ) );
233
+ }
234
+ cson_object_set_s(zEntry, zKeySize,
235
+ cson_value_new_integer( (cson_int_t)sz ));
236
+ /*cson_object_set(zEntry, "mtime",
237
+ cson_value_new_integer( (cson_int_t)ts ));*/
231238
}
232239
}
233240
db_finalize(&q);
234241
if(pM){
235242
manifest_destroy(pM);
236243
--- src/json_dir.c
+++ src/json_dir.c
@@ -106,11 +106,11 @@
106 ** Subdirectory names begin with "/". This causes them to sort
107 ** first and it also gives us an easy way to distinguish files
108 ** from directories in the loop that follows.
109 */
110 db_multi_exec(
111 "CREATE TEMP TABLE localfiles(x UNIQUE NOT NULL %s, u, sz);",
112 filename_collation()
113 );
114
115 if( zCI ){
116 Stmt ins;
@@ -118,12 +118,15 @@
118 ManifestFile *pPrev = 0;
119 int nPrev = 0;
120 int c;
121
122 db_prepare(&ins,
123 "INSERT OR IGNORE INTO localfiles VALUES(pathelement(:x,0), :u, "
124 "(SELECT size from blob where uuid=:s)"
 
 
 
125 ")"
126 );
127 manifest_file_rewind(pM);
128 while( (pFile = manifest_file_next(pM,0))!=0 ){
129 if( nD>0
@@ -139,10 +142,11 @@
139 continue;
140 }
141 db_bind_text(&ins, ":x", &pFile->zName[nD]);
142 db_bind_text(&ins, ":u", pFile->zUuid);
143 db_bind_text(&ins, ":s", pFile->zUuid);
 
144 db_step(&ins);
145 db_reset(&ins);
146 pPrev = pFile;
147 for(nPrev=0; (c=pPrev->zName[nD+nPrev]) && c!='/'; nPrev++){}
148 if( c=='/' ) nPrev++;
@@ -150,33 +154,33 @@
150 db_finalize(&ins);
151 }else if( zD && *zD ){
152 if( filenames_are_case_sensitive() ){
153 db_multi_exec(
154 "INSERT OR IGNORE INTO localfiles"
155 " SELECT pathelement(name,%d), NULL, NULL FROM filename"
156 " WHERE name GLOB '%q/*'",
157 nD, zD
158 );
159 }else{
160 db_multi_exec(
161 "INSERT OR IGNORE INTO localfiles"
162 " SELECT pathelement(name,%d), NULL FROM filename"
163 " WHERE name LIKE '%q/%%'",
164 nD, zD
165 );
166 }
167 }else{
168 db_multi_exec(
169 "INSERT OR IGNORE INTO localfiles"
170 " SELECT pathelement(name,0), NULL FROM filename"
171 );
172 }
173
174 if(zCI){
175 db_prepare( &q, "SELECT x as name, u as uuid, sz as size FROM localfiles ORDER BY x");
176 }else{/* UUIDs are all NULL. */
177 db_prepare( &q, "SELECT x as name FROM localfiles ORDER BY x");
178 }
179
180 zKeyName = cson_new_string("name",4);
181 cson_value_add_reference( cson_string_value(zKeyName) );
182 zKeyUuid = cson_new_string("uuid",4);
@@ -189,16 +193,18 @@
189 }
190
191 zPayload = cson_new_object();
192 cson_object_set_s( zPayload, zKeyName,
193 json_new_string((zD&&*zD) ? zD : "/") );
 
194 if(zUuid){
195 cson_object_set_s( zPayload, zKeyUuid,
196 cson_string_value(cson_new_string(zUuid, strlen(zUuid))) );
197 }
198 if( zCI ){
199 cson_object_set( zPayload, "checkin", json_new_string(zCI) );
 
200 }
201
202 while( (SQLITE_ROW==db_step(&q)) ){
203 cson_value * name = NULL;
204 char const * n = db_column_text(&q,0);
@@ -214,22 +220,23 @@
214 cson_object_set_s(zEntry, zKeyIsDir, cson_value_true() );
215 } else{
216 name = json_new_string( n );
217 }
218 cson_object_set_s(zEntry, zKeyName, name );
219 if( zCI ){
 
 
220 char const * u = db_column_text(&q,1);
221 sqlite_int64 const sz = db_column_int64(&q,2);
222 if(!isDir){
223 /* don't add the uuid/size for dir entries - that data refers
224 to one of the files in that directory :/. */
225 if(u && *u){
226 cson_object_set_s(zEntry, zKeyUuid, json_new_string( u ) );
227 }
228 cson_object_set_s(zEntry, zKeySize,
229 cson_value_new_integer( (cson_int_t)sz ));
230 }
231 }
232 }
233 db_finalize(&q);
234 if(pM){
235 manifest_destroy(pM);
236
--- src/json_dir.c
+++ src/json_dir.c
@@ -106,11 +106,11 @@
106 ** Subdirectory names begin with "/". This causes them to sort
107 ** first and it also gives us an easy way to distinguish files
108 ** from directories in the loop that follows.
109 */
110 db_multi_exec(
111 "CREATE TEMP TABLE localfiles(n UNIQUE NOT NULL %s, u, sz, mtime DEFAULT NULL);",
112 filename_collation()
113 );
114
115 if( zCI ){
116 Stmt ins;
@@ -118,12 +118,15 @@
118 ManifestFile *pPrev = 0;
119 int nPrev = 0;
120 int c;
121
122 db_prepare(&ins,
123 "INSERT OR IGNORE INTO localfiles VALUES("
124 /*0*/ "pathelement(:x,0),"
125 /*1*/ ":u, "
126 /*2*/ "(SELECT size from blob where uuid=:s), "
127 /*3: TODO: mtime*/" NULL"
128 ")"
129 );
130 manifest_file_rewind(pM);
131 while( (pFile = manifest_file_next(pM,0))!=0 ){
132 if( nD>0
@@ -139,10 +142,11 @@
142 continue;
143 }
144 db_bind_text(&ins, ":x", &pFile->zName[nD]);
145 db_bind_text(&ins, ":u", pFile->zUuid);
146 db_bind_text(&ins, ":s", pFile->zUuid);
147 /*db_bind_text(&ins, ":u3", pFile->zUuid);*/
148 db_step(&ins);
149 db_reset(&ins);
150 pPrev = pFile;
151 for(nPrev=0; (c=pPrev->zName[nD+nPrev]) && c!='/'; nPrev++){}
152 if( c=='/' ) nPrev++;
@@ -150,33 +154,33 @@
154 db_finalize(&ins);
155 }else if( zD && *zD ){
156 if( filenames_are_case_sensitive() ){
157 db_multi_exec(
158 "INSERT OR IGNORE INTO localfiles"
159 " SELECT pathelement(name,%d), NULL, NULL, NULL FROM filename"
160 " WHERE name GLOB '%q/*'",
161 nD, zD
162 );
163 }else{
164 db_multi_exec(
165 "INSERT OR IGNORE INTO localfiles"
166 " SELECT pathelement(name,%d), NULL, NULL, NULL FROM filename"
167 " WHERE name LIKE '%q/%%'",
168 nD, zD
169 );
170 }
171 }else{
172 db_multi_exec(
173 "INSERT OR IGNORE INTO localfiles"
174 " SELECT pathelement(name,0), NULL, NULL, NULL FROM filename"
175 );
176 }
177
178 if(zCI){
179 db_prepare( &q, "SELECT n as name, u as uuid, sz as size FROM localfiles ORDER BY n");
180 }else{/* UUIDs are all NULL. */
181 db_prepare( &q, "SELECT n as name FROM localfiles ORDER BY n");
182 }
183
184 zKeyName = cson_new_string("name",4);
185 cson_value_add_reference( cson_string_value(zKeyName) );
186 zKeyUuid = cson_new_string("uuid",4);
@@ -189,16 +193,18 @@
193 }
194
195 zPayload = cson_new_object();
196 cson_object_set_s( zPayload, zKeyName,
197 json_new_string((zD&&*zD) ? zD : "/") );
198 #if 0
199 if(zUuid){
200 cson_object_set_s( zPayload, zKeyUuid,
201 cson_string_value(cson_new_string(zUuid, strlen(zUuid))) );
202 }
203 #endif
204 if( zUuid ){
205 cson_object_set( zPayload, "checkin", json_new_string(zUuid) );
206 }
207
208 while( (SQLITE_ROW==db_step(&q)) ){
209 cson_value * name = NULL;
210 char const * n = db_column_text(&q,0);
@@ -214,22 +220,23 @@
220 cson_object_set_s(zEntry, zKeyIsDir, cson_value_true() );
221 } else{
222 name = json_new_string( n );
223 }
224 cson_object_set_s(zEntry, zKeyName, name );
225 if( zCI && !isDir){
226 /* don't add the uuid/size for dir entries - that data refers
227 to one of the files in that directory :/. */
228 char const * u = db_column_text(&q,1);
229 sqlite_int64 const sz = db_column_int64(&q,2);
230 /*sqlite_int64 const ts = db_column_int64(&q,3);*/
231 if(u && *u){
232 cson_object_set_s(zEntry, zKeyUuid, json_new_string( u ) );
233 }
234 cson_object_set_s(zEntry, zKeySize,
235 cson_value_new_integer( (cson_int_t)sz ));
236 /*cson_object_set(zEntry, "mtime",
237 cson_value_new_integer( (cson_int_t)ts ));*/
 
238 }
239 }
240 db_finalize(&q);
241 if(pM){
242 manifest_destroy(pM);
243

Keyboard Shortcuts

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