Fossil SCM
Minor cleanups and tinkering in /json/dir.
Commit
c1963c49b0a09e262ae261dc4d47ed57b56f7c45
Parent
5dcaeca7c1f146d…
1 file changed
+27
-20
+27
-20
| --- src/json_dir.c | ||
| +++ src/json_dir.c | ||
| @@ -106,11 +106,11 @@ | ||
| 106 | 106 | ** Subdirectory names begin with "/". This causes them to sort |
| 107 | 107 | ** first and it also gives us an easy way to distinguish files |
| 108 | 108 | ** from directories in the loop that follows. |
| 109 | 109 | */ |
| 110 | 110 | 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);", | |
| 112 | 112 | filename_collation() |
| 113 | 113 | ); |
| 114 | 114 | |
| 115 | 115 | if( zCI ){ |
| 116 | 116 | Stmt ins; |
| @@ -118,12 +118,15 @@ | ||
| 118 | 118 | ManifestFile *pPrev = 0; |
| 119 | 119 | int nPrev = 0; |
| 120 | 120 | int c; |
| 121 | 121 | |
| 122 | 122 | 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" | |
| 125 | 128 | ")" |
| 126 | 129 | ); |
| 127 | 130 | manifest_file_rewind(pM); |
| 128 | 131 | while( (pFile = manifest_file_next(pM,0))!=0 ){ |
| 129 | 132 | if( nD>0 |
| @@ -139,10 +142,11 @@ | ||
| 139 | 142 | continue; |
| 140 | 143 | } |
| 141 | 144 | db_bind_text(&ins, ":x", &pFile->zName[nD]); |
| 142 | 145 | db_bind_text(&ins, ":u", pFile->zUuid); |
| 143 | 146 | db_bind_text(&ins, ":s", pFile->zUuid); |
| 147 | + /*db_bind_text(&ins, ":u3", pFile->zUuid);*/ | |
| 144 | 148 | db_step(&ins); |
| 145 | 149 | db_reset(&ins); |
| 146 | 150 | pPrev = pFile; |
| 147 | 151 | for(nPrev=0; (c=pPrev->zName[nD+nPrev]) && c!='/'; nPrev++){} |
| 148 | 152 | if( c=='/' ) nPrev++; |
| @@ -150,33 +154,33 @@ | ||
| 150 | 154 | db_finalize(&ins); |
| 151 | 155 | }else if( zD && *zD ){ |
| 152 | 156 | if( filenames_are_case_sensitive() ){ |
| 153 | 157 | db_multi_exec( |
| 154 | 158 | "INSERT OR IGNORE INTO localfiles" |
| 155 | - " SELECT pathelement(name,%d), NULL, NULL FROM filename" | |
| 159 | + " SELECT pathelement(name,%d), NULL, NULL, NULL FROM filename" | |
| 156 | 160 | " WHERE name GLOB '%q/*'", |
| 157 | 161 | nD, zD |
| 158 | 162 | ); |
| 159 | 163 | }else{ |
| 160 | 164 | db_multi_exec( |
| 161 | 165 | "INSERT OR IGNORE INTO localfiles" |
| 162 | - " SELECT pathelement(name,%d), NULL FROM filename" | |
| 166 | + " SELECT pathelement(name,%d), NULL, NULL, NULL FROM filename" | |
| 163 | 167 | " WHERE name LIKE '%q/%%'", |
| 164 | 168 | nD, zD |
| 165 | 169 | ); |
| 166 | 170 | } |
| 167 | 171 | }else{ |
| 168 | 172 | db_multi_exec( |
| 169 | 173 | "INSERT OR IGNORE INTO localfiles" |
| 170 | - " SELECT pathelement(name,0), NULL FROM filename" | |
| 174 | + " SELECT pathelement(name,0), NULL, NULL, NULL FROM filename" | |
| 171 | 175 | ); |
| 172 | 176 | } |
| 173 | 177 | |
| 174 | 178 | 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"); | |
| 176 | 180 | }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"); | |
| 178 | 182 | } |
| 179 | 183 | |
| 180 | 184 | zKeyName = cson_new_string("name",4); |
| 181 | 185 | cson_value_add_reference( cson_string_value(zKeyName) ); |
| 182 | 186 | zKeyUuid = cson_new_string("uuid",4); |
| @@ -189,16 +193,18 @@ | ||
| 189 | 193 | } |
| 190 | 194 | |
| 191 | 195 | zPayload = cson_new_object(); |
| 192 | 196 | cson_object_set_s( zPayload, zKeyName, |
| 193 | 197 | json_new_string((zD&&*zD) ? zD : "/") ); |
| 198 | +#if 0 | |
| 194 | 199 | if(zUuid){ |
| 195 | 200 | cson_object_set_s( zPayload, zKeyUuid, |
| 196 | 201 | cson_string_value(cson_new_string(zUuid, strlen(zUuid))) ); |
| 197 | 202 | } |
| 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) ); | |
| 200 | 206 | } |
| 201 | 207 | |
| 202 | 208 | while( (SQLITE_ROW==db_step(&q)) ){ |
| 203 | 209 | cson_value * name = NULL; |
| 204 | 210 | char const * n = db_column_text(&q,0); |
| @@ -214,22 +220,23 @@ | ||
| 214 | 220 | cson_object_set_s(zEntry, zKeyIsDir, cson_value_true() ); |
| 215 | 221 | } else{ |
| 216 | 222 | name = json_new_string( n ); |
| 217 | 223 | } |
| 218 | 224 | 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 :/. */ | |
| 220 | 228 | char const * u = db_column_text(&q,1); |
| 221 | 229 | 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 ));*/ | |
| 231 | 238 | } |
| 232 | 239 | } |
| 233 | 240 | db_finalize(&q); |
| 234 | 241 | if(pM){ |
| 235 | 242 | manifest_destroy(pM); |
| 236 | 243 |
| --- 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 |